package com.sq.shortlink.project.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sq.shortlink.project.dao.entity.LinkStatsTodayDO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

/**
 * 短链接今日统计持久层
 * @author quan
 */
@Mapper
public interface LinkStatsTodayMapper extends BaseMapper<LinkStatsTodayDO> {

    /**
     * 短链接今日监控访问数据
     */
    @Insert("INSERT INTO t_link_stats_today (full_short_url,gid,date,today_pv,today_uv,today_uip,create_time,update_time,del_flag)\n" +
            "VALUES(#{linkStatsTodayDO.fullShortUrl},#{linkStatsTodayDO.gid},#{linkStatsTodayDO.date},#{linkStatsTodayDO.todayPv},#{linkStatsTodayDO.todayUv},#{linkStatsTodayDO.todayUIp},NOW(),NOW(),0) ON DUPLICATE KEY\n" +
            "UPDATE\n" +
            "today_pv = today_pv + #{linkStatsTodayDO.todayPv},today_uv = today_uv + #{linkStatsTodayDO.todayUv},today_uip = today_uip + #{linkStatsTodayDO.todayUIp}")
    void shortLinkStatsToday(@Param("linkStatsTodayDO") LinkStatsTodayDO linkStatsTodayDO);

}
